/**
 *  Class: Datastructures, CSI 326 Fall 2011
 *  Members: Christopher Nerf, Greg Shevach, Mesfin Solomon, Vidat Muslim
 *  Project: Project 1
 *  Scope: Implement a stack using one of the basic containers we have or will discuss. Example: A vector or list based stack.
 *  	   Implement a queue using one of the basic containers we have or will discuss. Example: A circular array or list based
 *		   queue
 *		   Develop and implement a palindrome checker that uses your stack and/or queue.
 *				 The data to be checked as a palindrome will consist of string characters, possibly containing whitespace and
 *				punctuation.
 *				 A palindrome reads the same forward as backward, ignoring case, whitespace and punctuation.
 *				 The strings to check will be stored in a file, one string per line. The file will contain the string quit to signify
 *				the end of file.
 *				 The strings can be of any length
 *  Version: 0.0 - Initial Pass
 */

/**
*
*
* This is our stack. It uses a doubly linked list. Implements a push, pop, getSize, isempty, toString (which removes all elements and empties the stack)
*
*
*/


public class Stack<T> 
{
	private DoubleList<T> ll;
	
	Stack ()
	{
	ll = new DoubleList<T>();
	}
	Stack(T e)
	{	
		DoubleNode<T> element = new DoubleNode<T>(e);
		ll = new DoubleList<T>(element);
	}
	
	public int getSize()
	{
		return ll.size();
	}
	
	public boolean isEmpty()
	{
		return ll.isEmpty();
	}
	
	public void push(T e)
	{
		ll.addElementToFront(e);
	}	
	
	public T pop()
	{
		return ll.removeFirst();		
	}
	
	//Pops all elements
	public String toString()
	{
		String allElements = "";
		try
		{
			int i = ll.size();
			//pop all elements in the stack, append to string
			while(i-- > 0)
				allElements += this.pop();
		}
		catch (Exception wtf)
		{
			//other exceptions, however, suck and must be dealt with
			wtf.printStackTrace();
			wtf.toString();
		}
		return allElements;
	}

}
